<?php
/*
 * File name : Agency.php
 * Description : Allows Donor to search for an Agency
 * Created By : Pratibha Awasthi
 */
include_once "basePage.php";

class Agency extends basePage{
	
	//Constructor
	public function __construct()
    {
    }
    
    // Provide an option for the subscriber to search for an agency based on the Service  Category/ City/ Neighbourhood
    public function search(){
    	
    		$con = mysql_connect('localhost','pa_user','secret_password');
			if (!$con){
		  		die('Could not connect: ' . mysql_error());
		  	}
		  
			mysql_select_db("TGS_GM_RESERVATION", $con);

			// Fetch all the available Neighbourhood / Service Category and the City option to be provided to the subscriber
			$resultServCat = mysql_query("SELECT distinct Description FROM TGS_GM_RESERVATION.tblcategory");
			
			$resultNeighbour = mysql_query("SELECT distinct NeighborhoodDescr FROM TGS_GM_RESERVATION.lkpneighborhoods");
			
			$resultCity = mysql_query("SELECT distinct City FROM TGS_GM_RESERVATION.tblagency");
			
		// Search options
    	echo <<<ESEARCH
		    <div id = "search">
			<h1> Search for Agency <br/> By </h1>
			<form action = "DisplayAgency.php" method = "post" name = "agency_page">
			<p>
				
			<input type = 'radio' name = 'agency_search' value = 'service_cat' onclick = "toggle('service');"> Service Category
			<input type = 'radio' name = 'agency_search' value = 'neighbourhood' onclick = "toggle('neighbour');"> Neighbourhood
			<input type = 'radio' name = 'agency_search' value = 'city' onclick = "toggle('city');"> City
			<input type = 'radio' name = 'agency_search' value = 'zip' onclick = "toggle('zip');"> Zip
		
			</p>
		
ESEARCH;
		echo <<<ESEARCHZIP
			 <!--<ul class= "agency_dropdown">-->
			 <!--<li id = "agency_dropdown_zip">-->
	        <!-- Search By Zip Code -->
	        <p>
			<input type= 'text' name= 'zipcode' id= 'zipcode' style= 'visibility:hidden'>
			</p>
	         <!--</li> -->                 
ESEARCHZIP;
		
		 // Search By City 
		 
		 echo '<p>';
		 echo '<select name="city" style= "visibility:hidden">';
    	 echo '<option value="0">Choose a City</option>';
    	 while($row = mysql_fetch_array($resultCity)){
			echo <<<ESEARCHCITY
    		<option> {$row['City']} </option>                      
ESEARCHCITY;
        }
		echo '</select>';
		echo '</p>';
		
		// Search By Neighbourhood
		echo '<p>';
		 
		echo '<select name="neighbour" style= "visibility:hidden">';
    	echo '<option value="0">Choose a Neighbourhood</option>';
    	while($row = mysql_fetch_array($resultNeighbour)){
    		echo <<<ESEARCHNEIGHBOUR
			<option> {$row['NeighborhoodDescr']} </option>            
ESEARCHNEIGHBOUR;
    	}
	    echo '</select>';
	    echo '</p>';
	    		
    	// Search By Service Category
    	
    	echo '<p>';
    	echo '<select name="servcat" style= "visibility:hidden">';
    	echo '<option value="0">Choose a Service Category</option>';
    	while($row = mysql_fetch_array($resultServCat)){
			echo <<<ESEARCHCAT
    		<option> {$row['Description']} </option>                    
ESEARCHCAT;
    	}
		echo '</select>';
		echo '</p>';

		// Submit and the Back Buttons
		echo <<<ESUBMIT
		<p><br/><br/><input type = 'submit' name = 'submit' value = 'Search Agency'></p>
		
		<p><input type = 'submit' name = 'submit' value = 'Back' onclick='history.go(-1);'></p>
		</form>    
	    </div> 
	    <script src="../template/agency.js" type="text/javascript"></script>	
ESUBMIT;
		mysql_close($con);
    }
}

$page = new Agency();
$page->header();
$page->top_menu_donor();
$page->search();
$page->footer();

?>